package com.googlecode.spruce.web.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.googlecode.spruce.dao.ServiceGroupDao;
import com.googlecode.spruce.domain.ServiceGroup;

@Controller
@RequestMapping("/v1/servicegroup")
public class ServiceGroupController
{

    @Autowired
    private ServiceGroupDao serviceGroupDao;

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public @ResponseBody
    ServiceGroup getById(@PathVariable Integer id)
    {
        return serviceGroupDao.findByID(id);
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public @ResponseBody
    Integer create(final @RequestBody ServiceGroup sg)
    {
        Assert.notNull(sg);
        Assert.hasText(sg.getName());

        return serviceGroupDao.save(sg);
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public @ResponseBody
    List<ServiceGroup> getAll()
    {
        return serviceGroupDao.getAll();
    }
}
